package com.supermap.dataservice.cloud.science.assets;

import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author aqua
 * @description
 * @date 2019年10月28 17:52
 * @email 1301584033@qq.com
 */
@Mapper
public interface FlieDocMapper {


    @Select("select rolecode from cqpamiss.t_s_role where id=\n" +
            "(select t1.roleid from cqpamiss.t_s_role_user t1 where t1.userid=#{userId} limit 1)")
    String getUserRole(@Param("userId")String userId);

    @Select("select * from t_files_upload where id=#{id} and userId=#{userId} and del_flg=0")
    List<Map<String,Object>> getObject(@Param("id")Integer id,@Param("userId")String userId);

    //获取区域下拉
    @Select("select t1.areacode,t1.areaname from t_area t1 where left(t1.areacode) <> '99' and " +
            "if(#{areaCode} is null,1=1,t1.areacode like concat(#{areaCode},'%')) order by areacode asc")
    List<Map<String,Object>> mapGetArea(@Param("areaCode") String areaCode);

    //查询
    @Select("select * from t_files_upload t1 where t1.areaCode like concat(#{areaCode},'%') and  t1.del_flg=0  order by t1.`date` desc limit #{page},#{size}")
    List<Map<String,Object>> getFileDoc(@Param("areaCode") String areaCode,@Param("page") Integer page,@Param("size") Integer size);


    //查询
    @Select("select count(1) from t_files_upload t1 where t1.areaCode like concat(#{areaCode},'%') and  t1.del_flg=0  order by t1.`date` desc limit #{page},#{size}")
    Integer getFileDoc1(@Param("areaCode") String areaCode,@Param("page") Integer page,@Param("size") Integer size);

    //添加
    @Insert("insert into t_files_upload(title,fileName,`date`,userId,areaCode) values(#{title},#{fileName},#{date},#{userId},#{areaCode})")
    void insert(@Param("fileName") String fileName,@Param("title") String title,@Param("date")String date,@Param("userId") String userId,@Param("areaCode") String areaCode);

    //删除
    @Update("update t_files_upload set deluserId=#{userId},deldate=#{date},del_flg=1 where id=#{id}")
    void delFileDoc(@Param("id") Integer id,@Param("userId") String userId,@Param("date") String date);
}
